package com.netpace.iem.umair.model;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public class Expense {
	// State
	private int id;
	private List<Item> items;
	private List<Label> labels;
	private Category category;
	private Calendar date;
	private double total;
	
	// Constructors
	public Expense() {
		items = new ArrayList<Item>();
		labels = new ArrayList<Label>();
	}
	public Expense(int id, List<Item> items, List<Label> labels, Category category, Calendar date) {
		this.id = id;
		this.items = items;
		this.labels = labels;
		this.category = category;
		this.date = date;
		this.total = calcTotal();
	}
	public Expense(int id, Category category, Calendar date, double total) {
		this(id, new ArrayList<Item>(), new ArrayList<Label>(), category, date);
		this.total = total;
	}

	// Getters
	public int getId() {
		return id;
	}
	public List<Item> getItems() {
		return items;
	}
	public List<Label> getLabels() {
		return labels;
	}
	public Category getCategory() {
		return category;
	}
	public Calendar getDate() {
		return date;
	}
	public double getTotal() {
		return total;
	} 
	
	// Setters
	public void setId(int id) {
		this.id = id;
	}
	public void setItems(List<Item> items) {
		this.items = items;
	}
	public void setLabels(List<Label> labels) {
		this.labels = labels;
	}
	public void setCategory(Category category) {
		this.category = category;
	}
	public void setDate(Calendar date) {
		this.date = date;
	}
	public void setTotal(double total) {
		this.total = total;
	}

	// Helper Methods
	private double calcTotal() {
		double total = 0; 
		for (Item t : items) {
			total += t.getAmount();
		}
		
		return total;
	}
}

